﻿using Max.PH5_2004A.Shopping.Domain;
using Max.PH5_2004A.Shopping.DTO.Goods;
using Max.PH5_2004A.Shopping.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Max.PH5_2004A.Shopping.API.Controllers
{
    [Route("category")]
    [ApiController]
    public class CategoryController : ControllerBase
    {
        //依赖注入分类服务接口
        ICategoryService _serice;

        public CategoryController(ICategoryService serice)
        {
            _serice = serice;
        }


        [HttpGet("select")]
        public IActionResult Select()
        {
            var list =_serice.Select().ToList();
            return Ok(list);
        }

        [HttpPost]
        public IActionResult Add()
        {
            var list = new List<CategoryModel>();
            //list.Add(new CategoryModel {  Name="服装",PId=0});
            //list.Add(new CategoryModel { Name = "短装", PId = 1 });
            //list.Add(new CategoryModel { Name = "羽绒服", PId = 1 });
            //list.Add(new CategoryModel { Name = "居家", PId = 0 });
            //list.Add(new CategoryModel { Name = "床上用品", PId = 4 });
            //list.Add(new CategoryModel { Name = "家用电器", PId = 4 });
            list.Add(new CategoryModel { Name = "日用电器", PId = 4 });
            var result = _serice.Insert(list);

            return Ok(result);
        }

        //private void GetCategory()
        //{
        //    //每次都是执行where条件，然后循环这个结果
        //    var list = _serice.Select(x => x.PId == 0).ToList();

        //    foreach (var item in list)
        //    {
        //        var list2 = _serice.Select(x => x.PId == item.Id);

        //        foreach (var k in list2)
        //        {
        //            var list3 = _serice.Select(x => x.PId == k.Id);

        //            foreach (var j in list3)
        //            {
        //                var list4 = _serice.Select(x => x.PId == j.Id);
        //                foreach (var p in list4)
        //                {

        //                }
        //            }
        //        }
        //    }
        //}

        //private void GetCategory(int id)
        //{
        //    var list = _serice.Select(x => x.PId == id).ToList();

        //    foreach (var item in list)
        //    {
        //        GetCategory(item.Id);
        //    }
        //}




        [HttpGet]
        public IActionResult GetCategoryList()
        {
            var list = _serice.GetCategory(0);

            return Ok(list);
        }
        
    }
}
